﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections.Specialized;

using Mvc.XForms.Utilities;
using System.Web.UI.WebControls;

namespace Mvc.XForms.UI {
	public static class ISortedParametersExtensions {
		public static string SortExpressionFromCollection(this ISortedParameters s, NameValueCollection collection, string defaultSortExpression) {
			var sortBy = collection[s.SortExpressionKey];

			if (!string.IsNullOrEmpty(sortBy))
				return sortBy;

			return defaultSortExpression;
		}

		public static SortDirection SortDirectionFromCollection(this ISortedParameters s, NameValueCollection collection, SortDirection defaultSortDirection) {
			var sortDirection = collection[s.SortDirectionKey];

			if (!string.IsNullOrEmpty(sortDirection)) {
				var sortExpression = (SortDirection)Convert.ToInt32(sortDirection);
				return sortExpression;
			}

			return defaultSortDirection;
		}
	}
}